home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1996 / MacHack 1996.toast / Hacks / Hacks ’92 / Run & Stumpy / source / makestartupfolder.cp < prev    next >
Encoding:
Text File  |  1992-06-18  |  2.3 KB  |  100 lines  |  [TEXT/MPS ]

  1. #include <files.h>
  2. #include <resources.h>
  3. #include <folders.h>
  4. #include <errors.h>
  5. #include <icons.h>
  6. #include <toolutils.h>
  7.  
  8. #include "inttypes.h"
  9. #include "specs.h"
  10. #include "getfoldername.h"
  11. #include "makestartupfolder.h"
  12.  
  13. #define rootDirID        2
  14. #define iconresid        -16455
  15.  
  16. #define diskiconresource    200
  17.  
  18. #define thestringlist        200
  19. #define iconfilestring        1
  20.  
  21. extern OSErr installfoldericons( int16 resid, const FSSpec& folder );
  22.  
  23. OSErr makestartupfolder( const FSSpec& volume )
  24.   {
  25.     Str255 name;
  26.     OSErr error = getfoldername( kStartupFolderType, name );
  27.     if ( error != noErr )
  28.         return error;
  29.     
  30.     FSSpec folder;
  31.     error = childfsspec( volume, name, folder );
  32.     if ( error != noErr && error != fnfErr )
  33.         return error;
  34.     
  35.     if ( error == fnfErr )
  36.       {
  37.         int32 dirid;
  38.         error = FSpDirCreate( &folder, 0, &dirid );
  39.       }
  40.     
  41.     (void)installfoldericons( startupFolderIconResource, folder );
  42.     (void)installfoldericons( diskiconresource, volume );
  43.     return noErr;
  44.   }
  45.  
  46. OSErr installfoldericons( int16 resid, const FSSpec& folder )
  47.   {
  48.     FSSpec iconfile;
  49.     Str255 iconfilename;
  50.     GetIndString( iconfilename, thestringlist, iconfilestring );
  51.     OSErr error = childfsspec( folder, iconfilename, iconfile );
  52.     if ( error == noErr )
  53.         return dupFNErr;
  54.     if ( error != fnfErr )
  55.         return error;
  56.     
  57.     FSpCreateResFile( &iconfile, 0, 0, 0 );
  58.     if ( ResError() != noErr )
  59.         return ResError();
  60.  
  61.     int16 iconref= FSpOpenResFile( &iconfile, fsRdWrPerm );
  62.     if ( ResError() != noErr )
  63.         return ResError();
  64.  
  65.     static OSType types[]= { 'icl4', 'icl8', 'ICN#', 'ics#', 'ics4', 'ics8', 0 };
  66.     for ( uint16 i=0; types[i]!=0; i++ )
  67.       {
  68.         Handle res= GetResource( types[i], resid );
  69.         if ( res == 0 )
  70.             continue;
  71.         
  72.         DetachResource( res );
  73.         AddResource( res, types[i], iconresid, "\p" );
  74.         WriteResource( res );
  75.       }
  76.     
  77.     CloseResFile( iconref );
  78.     
  79.     FInfo info;
  80.     if ( FSpGetFInfo( &iconfile, &info ) == noErr )
  81.       {
  82.         info.fdFlags |= fInvisible;
  83.         info.fdFlags &= ~0x0100;
  84.         (void)FSpSetFInfo( &iconfile, &info );
  85.       }
  86.     
  87.     CInfoPBRec pb;
  88.     pb.dirInfo.ioCompletion=0;
  89.     pb.dirInfo.ioNamePtr= (StringPtr)&folder.name;
  90.     pb.dirInfo.ioVRefNum= folder.vRefNum;
  91.     pb.dirInfo.ioFDirIndex= 0;
  92.     pb.dirInfo.ioDrDirID= folder.parID;
  93.     if ( PBGetCatInfoSync( &pb ) == noErr )
  94.       {
  95.         pb.dirInfo.ioDrDirID= folder.parID;
  96.         pb.dirInfo.ioDrUsrWds.frFlags = 0x400;
  97.         (void)PBSetCatInfoSync( &pb );
  98.       }
  99.   }
  100.